package TestTIjiao;



import java.sql.*;

/**
 * @author 李某
 * * @date 2021/11/22
 * *物有本末，事有终始。知其先后者，则近道矣！
 * *荷花开满池塘的前一天还是半塘荷花半塘云。
 */
public class JDBCConnect {
    public static void main(String[] args) {
            adddata("1","1","1");
    }

    public static void JDBCConnect(){

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("驱动初始化成功");

    }

    public static void adddata(String id,String name,String pwd){
        String a = id;
        String b = name;
        String c = pwd;

        PreparedStatement p = null;

        try (
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8",
                        "root", "root");
                Statement s = con.createStatement();
        ){
            String sql = "insert into user values(?,?,?)";
            p = con.prepareStatement(sql);
            p.setObject(1,a);
            p.setObject(2,b);
            p.setObject(3,c);
            p.executeUpdate();
            con.close();
        }catch ( SQLException e){
            e.printStackTrace();
        }finally {
            try {
                p.close();

            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }



}

class CRUD{

    // 增加
    public static void c (int id,String name,String pwd){
        String sql = "insert into user values(?,?,?)";
    }

}